package com.wss.merchant.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wss.merchant.domain.CommonResult;
import com.wss.merchant.domain.DlNewProductspecs;
import com.wss.merchant.service.DlNewProductspecsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品规格表 前端控制器
 * </p>
 *
 * @author wss
 * @since 2021-03-06
 */
@Controller
@RequestMapping("/productSpecs")
public class DlNewProductspecsController {
    @Autowired
    private DlNewProductspecsService dlNewProductspecsService;
    //根据产品查询所有规格
    @RequestMapping("/get")
    @ResponseBody
    public CommonResult get(@RequestBody Map map){
        QueryWrapper<DlNewProductspecs> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid",map.get("pid"));
        List<DlNewProductspecs> list = dlNewProductspecsService.list(queryWrapper);
        return new CommonResult(200,"查询成功",list);
    }
    //给产品添加规格
    @RequestMapping("/add")
    @ResponseBody
    public CommonResult add(@RequestBody DlNewProductspecs dlNewProductspecs){
        dlNewProductspecsService.save(dlNewProductspecs);
        return new CommonResult(200,"添加规格成功");
    }

    //修改规格
    @RequestMapping("/alter")
    @ResponseBody
    public CommonResult alter(@RequestBody DlNewProductspecs dlNewProductspecs){
        dlNewProductspecsService.updateById(dlNewProductspecs);
        return new CommonResult(200,"修改成功");
    }

    //删除规格
    @RequestMapping("/delete")
    @ResponseBody
    public CommonResult delete(@RequestBody DlNewProductspecs dlNewProductspecs){
        dlNewProductspecsService.removeById(dlNewProductspecs.getId());
        return new CommonResult(200,"删除成功");
    }



}

